package wwj.bean;

import java.util.ArrayList;

public class HomeData {
    //    通用页码信息
    private int curPage;   //记录当前第几页
    private final int numPerPage = 2;  //记录一页显示多少条数据
    private int totalElement; //表示查到符合条件的所有记录数
    private int totalPages; //总页码数：符合条件的记录数和一页显示多少条数据计算

    private int navigateFirstPage; //前端页面上页码部分上第一个页码
    private int navigateLastPage; //最后一个页码
    private final int navigatePages = 5;  //每条页码展示五个12345 678910
    private int navigatePageCircle;  //记录切换多少次 导航栏切换次数


    @Override
    public String toString() {
        return "HomeData{" +
                "curPage=" + curPage +
                ", numPerPage=" + numPerPage +
                ", totalElement=" + totalElement +
                ", totalPages=" + totalPages +
                ", navigateFirstPage=" + navigateFirstPage +
                ", navigateLastPage=" + navigateLastPage +
                ", navigatePages=" + navigatePages +
                ", navigatePageCircle=" + navigatePageCircle +
                ", sort=" + sort +
                ", keyWord='" + keyWord + '\'' +
                ", commodity=" + commodity +
                '}';
    }

    //    主页的条件设置
    private int sort; //分类信息：值为0不分类查询 1就是分类
    private String keyWord;//关键字查询

    private ArrayList<CommodityBean> commodity;//商品集合

    public HomeData(int curPage, int sort, String keyWord) {
        this.curPage = curPage;
        this.sort = sort;
        this.keyWord = keyWord;
    }

    public HomeData() {
    }

    public int getCurPage() {
        return curPage;
    }

    public void setCurPage(int curPage) {
        this.curPage = curPage;
    }

    public int getNumPerPage() {
        return numPerPage;
    }

    public int getTotalElement() {
        return totalElement;
    }

    //符合条件的所有记录数
    public void setTotalElement(int totalElement) {
        this.totalElement = totalElement;
//        计算其余成员变量
        setTotalPages(((this.totalElement - 1) / numPerPage) + 1);//总页码数=（总记录数-1）/（一页展示多少数据）+1
        setNavigatePageCircle((curPage - 1) / navigatePages);//（当前页码-1）/导航栏展示个数=记录切换次数
        setNavigateFirstPage(navigatePageCircle * navigatePages + 1); //切换次数*导航栏展示个数+1=第一个页码

        setNavigateLastPage(Math.min(navigatePageCircle * navigatePages + 5, totalPages));
    }

    public int getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public int getNavigateFirstPage() {
        return navigateFirstPage;
    }

    public void setNavigateFirstPage(int navigateFirstPage) {
        this.navigateFirstPage = navigateFirstPage;
    }

    public int getNavigateLastPage() {
        return navigateLastPage;
    }

    public void setNavigateLastPage(int navigateLastPage) {
        this.navigateLastPage = navigateLastPage;
    }

    public int getNavigatePages() {
        return navigatePages;
    }

    public int getNavigatePageCircle() {
        return navigatePageCircle;
    }

    public void setNavigatePageCircle(int navigatePageCircle) {
        this.navigatePageCircle = navigatePageCircle;
    }

    public int getSort() {
        return sort;
    }

    public void setSort(int sort) {
        this.sort = sort;
    }

    public String getKeyWord() {
        return keyWord;
    }

    public void setKeyWord(String keyWord) {
        this.keyWord = keyWord;
    }

    public ArrayList<CommodityBean> getCommodity() {
        return commodity;
    }

    public void setCommodity(ArrayList<CommodityBean> commodity) {
        this.commodity = commodity;
    }
}


